package org.noka.select;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.system.BugInfoWrint;
import org.nokatag.tagjava.NokaTag;
/**
 * 弹出选择框
 * @author rebin
 *
 */
public class SelectButton extends  NokaTag{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3636998880912946061L;
	private  JspWriter jspOut =null;
	
	private String id = null;
	private String name = null;
	private String width = "120";
	private String bheight = "500";//弹出框的高
	private String bwidth = "600";//弹出框的宽
	private String value = null;//值
	private String text = null;//显示值
	private String readonly=null;//只读
	private String disabled = null;
	private String allownull="true";//允许为空
	private String placeholder = null;
	private String lotype = "iframe";//加载类型
	private String onopen=null;//方法名
	private String onclose=null;//方法名
	
	public int doStartTag()throws JspException{
		try{
			jspOut= pageContext.getOut();
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			StringBuilder body = new StringBuilder();
			body.append(potjs(request));//js框架
			body.append(selectCss(request));
			body.append(selectButtonjs(request));//select js
			body.append(nkBoxJsAndCss(request));
			body.append("<div id=\""+id+"_sDiv\">");
			body.append("<div id=\""+id+"_selectDiv\" style=\"float:left;\"></div>");
			body.append("<div id=\""+id+"_BoxDiv\" style=\"display:none;\">");//弹出内容
			jspOut.write(body.toString());
		}catch(Exception se){
			 BugInfoWrint.Print(se);
		}
		return EVAL_BODY_INCLUDE;
	}
	public int doEndTag() throws JspException {
		try {
				StringBuilder body = new StringBuilder();
				HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
				String basePath = basepath(request);
				String BHeight=LenNumber(bheight);
				String BWidth=LenNumber(bwidth);
				String Width=LenNumber(width);
				FormHtmlInsertid(getId(),getName(),getValue());
				body.append("</div>");
				body.append("</div>");
				body.append("<script type=\"text/javascript\">");
				//---------------显示树形菜单---------------------------
				body.append("Event.observe(document, 'dom:loaded', function() {");
				body.append("var sfg"+id+" = {");
				body.append("id:'"+id+"',");//id
				body.append("rurl:'"+basePath+"',");//根url
				body.append("name:'"+(name==null?id:name)+"',");//名字
				body.append("width:"+Width+",");//宽
				body.append("bheight:"+BHeight+",");//弹出框高
				body.append("bwidth:"+BWidth+",");//弹出框宽
				body.append("value:'"+(value==null?"":value)+"',");//值
				body.append("svalue:'"+(text==null?"":text)+"',");//显示值
				body.append("readonly:'"+(readonly==null?"":readonly)+"',");//只读
				body.append("disabled:'"+(disabled==null?"":disabled)+"',");
				body.append("allownull:"+allownull+",");
				body.append("lotype:'"+lotype+"',");
				body.append("openfunction:function(){"+(onopen==null?"":""+onopen+"();")+"},");//onchange
				body.append("closefunction:function(){"+(onclose==null?"":""+onclose+"();")+"},");//onchange
				body.append("placeholder:'"+(placeholder==null?"":placeholder)+"'");
				body.append("};");
				body.append("var nr"+id+" = new nselectbutton(sfg"+id+");");
				body.append("nr"+id+".show();");
				body.append("});");
				body.append("</script>");
				pageContext.getOut().write(body.toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
		return EVAL_PAGE;
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}


	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getReadonly() {
		return readonly;
	}

	public void setReadonly(String readonly) {
		this.readonly = readonly;
	}

	public String getAllownull() {
		return allownull;
	}

	public void setAllownull(String allownull) {
		this.allownull = allownull;
	}

	public String getPlaceholder() {
		return placeholder;
	}

	public void setPlaceholder(String placeholder) {
		this.placeholder = placeholder;
	}

	public JspWriter getJspOut() {
		return jspOut;
	}

	public void setJspOut(JspWriter jspOut) {
		this.jspOut = jspOut;
	}

	public String getBheight() {
		return bheight;
	}

	public void setBheight(String bheight) {
		this.bheight = bheight;
	}

	public String getBwidth() {
		return bwidth;
	}

	public void setBwidth(String bwidth) {
		this.bwidth = bwidth;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getLotype() {
		return lotype;
	}
	public void setLotype(String lotype) {
		this.lotype = lotype;
	}
	public String getOnopen() {
		return onopen;
	}
	public void setOnopen(String onopen) {
		this.onopen = onopen;
	}
	public String getOnclose() {
		return onclose;
	}
	public void setOnclose(String onclose) {
		this.onclose = onclose;
	}
	public String getDisabled() {
		return disabled;
	}
	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}
	

	
}
